package cn.tedu.dao;

import cn.tedu.entity.User;
import cn.tedu.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDao {
    public User login(String username, String password) {
        //获取链接
        try(Connection conn= DBUtils.getConn()) {
            String sql = "select * from vrduser where username=? and password=?" ;
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,username);
            ps.setString(2,password);
            ResultSet rs = ps.executeQuery();
            if (rs.next()){
                int id = rs.getInt(1);
                String name = rs.getString(2);
                String pwd = rs.getString(3);
                System.out.println(id+name+pwd);
                return new User(id,name,pwd);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }
}
